using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework;

namespace StupidSpaceThing
{
	[Flags]
	internal enum TextAlign { None = 1, Vertical = 2, Horizontal = 4, Bottom = 8, Both = Vertical | Horizontal };

	internal class TextGuide : Guide
	{
		private string text;
		private SpriteFont font;
		private TextAlign align;
		private float scale;
		private Color color;

		public TextGuide(string text, SpriteFont font, double duration) : this(text, font, TextAlign.None, 1, Color.White, duration, null) {			
		}
		public TextGuide(string text, SpriteFont font, TextAlign align, double duration)
			: this(text, font, align, 1, Color.White, duration, null) {
		}

		public TextGuide(string text, SpriteFont font, TextAlign align, float scale, Color color, double duration, GuideCallback callback)
			: base(duration, callback) {
			this.text = text;
			this.font = font;
			this.align = align;
			this.scale = scale;
			this.color = color;
		}

		public override void Draw(SpriteBatch spriteBatch) {
#if XBOX
			int leftOffset = 50;
			int topOffset = 30;
#else
			int leftOffset = 10;
			int topOffset = 10;
#endif
			if( (align & TextAlign.Horizontal) != 0 ) {
				leftOffset = (int)(spriteBatch.GraphicsDevice.Viewport.Width / 2 - (font.MeasureString(text).X * scale) / 2);
			}
			if( (align & TextAlign.Vertical) != 0 ) {
				topOffset = (int)(spriteBatch.GraphicsDevice.Viewport.Height / 2 - (font.MeasureString(text).Y * scale) / 2);
			}
			if( (align & TextAlign.Bottom) != 0 ) {
				topOffset = (int)(spriteBatch.GraphicsDevice.Viewport.Height - (font.MeasureString(text).Y * scale) / 2 - font.MeasureString(text).Y * scale);
#if XBOX
				topOffset -= 20;
#endif
			}
			spriteBatch.DrawString(font, text, new Vector2(leftOffset - 1, topOffset - 1), GetColor(Color.Black), 0, Vector2.Zero, scale, SpriteEffects.None, 0);
			spriteBatch.DrawString(font, text, new Vector2(leftOffset, topOffset), GetColor(color), 0, Vector2.Zero, scale, SpriteEffects.None, 0);
			base.Draw(spriteBatch);
		}
	}
}
